package org.jet.emall.log;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-04-14 14:27
 */



import org.jet.emall.rbac.dto.AdminLoginLogDTO;
import org.jet.emall.rbac.dto.AdminOpLogDTO;

import java.time.LocalDateTime;


/**
 * 日志对象创建工厂
 */
public class LogFactory {

    /**
     * 创建操作日志
     */
    public static AdminOpLogDTO createOperationLog(Integer userId, String username, Integer roleId, String roleName,
                                                   LogType logType, String className, String method, String args,
                                                   String reqUrl, String func, OpResultType success, String returnResult,
                                                   String menu, String ip, String userAgent, Integer spendTime, LocalDateTime opTime){
        AdminOpLogDTO adminOpLog = new AdminOpLogDTO();
        adminOpLog.setUserId(userId);
        adminOpLog.setUsername(username);
        adminOpLog.setRoleId(roleId);
        adminOpLog.setRoleName(roleName);
        adminOpLog.setOpType(logType.code);
        adminOpLog.setClassName(className);
        adminOpLog.setMethod(method);
        adminOpLog.setArgs(args);
        adminOpLog.setReqUrl(reqUrl);
        adminOpLog.setFunc(func);
        adminOpLog.setSuccess(success.code);
        adminOpLog.setReturnResult(returnResult);
        adminOpLog.setMenu(menu);
        adminOpLog.setIp(ip);
        adminOpLog.setUserAgent(userAgent);
        adminOpLog.setSpendTime(spendTime);
        adminOpLog.setOpTime(opTime);
        return adminOpLog;
    }

    /**
     * 创建登录日志
     */
    public static AdminLoginLogDTO createLoginLog(Integer userId, String username, Integer roleId, String roleName,
                                                  String ip, String userAgent, LogType logType, LocalDateTime loginTime) {
        AdminLoginLogDTO adminLoginLog = new AdminLoginLogDTO();
        adminLoginLog.setUserId(userId);
        adminLoginLog.setUsername(username);
        adminLoginLog.setRoleId(roleId);
        adminLoginLog.setRoleName(roleName);
        adminLoginLog.setIp(ip);
        adminLoginLog.setUserAgent(userAgent);
        adminLoginLog.setOpType(logType.code);
        adminLoginLog.setLoginTime(loginTime);
        return adminLoginLog;
    }
}
